package demo.entrymain;

import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.util.InputMismatchException;
import java.util.Scanner;

import demo.bean.Admin;
import demo.bean.Client;
import demo.factor.PeoFactory.PeoFactory;

public class EntryMain {
	
	//一开始写入管理员的信息
	static{
		try
		(
			ObjectOutputStream out1=new ObjectOutputStream(new FileOutputStream("Admin.dat"));
				){
			out1.writeObject(new Admin("0001","666"));
		}catch(Exception e)
		{}				
	}

	public static void main(String[] args) {
		
		Admin admin=PeoFactory.fa.readAdmin();
		System.out.println(admin);
		//入口
		mainMenu();
		start();
		
		
//测试内容：				
//		System.out.println(IFactory.addAGoods(new Goods("apple",12.0,100)));
//		System.out.println(IFactory.addAGoods(new Goods("apple",12.0,100)));
//		System.out.println(IFactory.addAGoods(new Goods("apple",12.0,100)));
//		System.out.println(IFactory.selectAllGoods());
//		System.out.println(IFactory.addClient(new Client("wp","123")));
//		System.out.println(IFactory.addClient(new Client("wp","123")));
//		System.out.println(IFactory.selectAllClient());
//		System.out.println(IFactory.addClient(new Client("wp1","123")));
//		System.out.println(IFactory.addClient(new Client("wp2","123")));
//		System.out.println(IFactory.addClient(new Client("wp2","123")));
//		System.out.println(IFactory.selectAllClient());
//		System.out.println(IFactory.addClient(new Client("wp1","123")));
//		System.out.println(IFactory.deleteClient(87));
//		System.out.println(IFactory.selectAllClient());
	//这里比较重要，封装的数据不是相等的	
		/*Integer a=666;
		Integer b=666;
		System.out.println(a==b);*/
		
//		System.out.println(IFactory.addAGoods(new Goods("apple",12.0,100)));
//		System.out.println(IFactory.addAGoods(new Goods("apple",12.0,100)));
//		System.out.println(IFactory.selectAllGoods());
//		System.out.println(IFactory.deleteGoods(10));
//		System.out.println(IFactory.addAGoods(new Goods("apple1",12.0,100)));
//		System.out.println(IFactory.selectAllGoods());	
	}
	
	
	
	
	public static void mainMenu()
	{
		System.out.println("-----------------------------------");
		System.out.println("选择登录方式（选择序号）：");
		System.out.println("1管理员登录");
		System.out.println("2顾客登录");
		System.out.println("3顾客注册");
		System.out.println("4退出系统");
	}
	public static void start()
	{
		Scanner in =new Scanner(System.in);
		while(true)
		{
			int a=0;
			try{
				a=in.nextInt();
			}catch(InputMismatchException e){
				System.err.println("请输入数字:");
				start();
			}
			
			if(a==1)
			{
				Admin.adminLogin();break;
			}else if(a==2){
				Client.clieLogin();break;
			}else if(a==3){
				Client.register();break;
			}else if(a==4){
				System.out.println("您已经退出系统！");
				System.exit(1);
			}else{
				System.err.println("输错数字了重新输入：");
			}
		}
	}
	
	

}
